package com.bckj.freshnow.order.trade.fsm;

import com.bckj.fastboot.core.execution.ExecutionContext;
import com.bckj.freshnow.goods.model.GoodsSkuRequest;
import com.bckj.freshnow.goods.model.GoodsSkuResponse;
import com.bckj.freshnow.order.entity.TradeItem;
import com.bckj.freshnow.order.entity.TradeOrder;
import com.bckj.freshnow.order.entity.TradeParentOrder;
import com.bckj.freshnow.order.model.TradeItemRequest;
import com.bckj.freshnow.order.trade.fsm.enums.TradeOrderEventEnum;
import com.bckj.freshnow.order.trade.fsm.enums.TradeOrderStatusEnum;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Data
public class TradeOrderContext implements ExecutionContext {

    TradeOrderStatusEnum from;
    TradeOrderStatusEnum to;
    TradeOrderEventEnum event;

    /**
     * 父订单编码
     */
    private String parentOrderNo;
    /**
     * 订单ID
     */
    private Long orderId;
    /**
     * 是否父订单
     */
    private Integer isParent;
    /**
     * 订单类型
     */
    private int orderType;
    /**
     * 业务身份编码
     */
    private String bizIdCode;
    /**
     * 请求
     */
    private Object request;
    /**
     * 响应
     */
    private Object response;
    /**
     * 检查扩展
     */
    private List<String> checkExtensions;
    /**
     * 操作扩展
     */
    private List<String> extensions;
    /**
     * 交易订单实体
     */
    private TradeOrder tradeOrder;
    /**
     * 父订单
     */
    private TradeParentOrder parentOrder;

    private Map<String, GoodsSkuResponse> skuInfo;

    private List<TradeItemRequest> itemList;

    private List<TradeItem> successfulItems;

    private int execFlag;

    /**
     * 根据订单类型和bizIdCode创建
     */
    public static TradeOrderContext create(int orderType, String bizIdCode) {
        TradeOrderContext ctx = new TradeOrderContext();
        ctx.setOrderType(orderType);
        ctx.setBizIdCode(bizIdCode);
        return ctx;
    }

    /**
     * 根据订单ID和是否父订单创建
     */
    public static TradeOrderContext create(Long orderId, Integer isParent) {
        TradeOrderContext ctx = new TradeOrderContext();
        ctx.setOrderId(orderId);
        ctx.setIsParent(isParent);
        return ctx;
    }
}
